<?php

class base_static_app
{
    static private $__instance = [];
    private $__setting = null;

    public function __construct($app_id)
    {
        $this->app_id = $app_id;
        $this->app_dir = APP_DIR . '/' . $app_id;
        $this->public_app_dir = PUBLIC_DIR . '/app/' . $app_id;

        $this->res_url = kernel::get_app_statics_host_url() . '/' . $app_id . '/statics';
		$this->res_url = kernel::get_app_statics_host_url().'/'.$app_id.'/statics';
		$this->res_full_url = kernel::get_app_statics_host_url().'/'.$app_id.'/statics';
		$this->lang_url = kernel::get_app_statics_host_url().'/'.$app_id.'/lang';
		$this->lang_full_url = kernel::get_app_statics_host_url().'/'.$app_id.'/lang';
		$this->widgets_url = kernel::get_app_statics_host_url().'/'.$app_id.'/widgets';
        $this->widgets_full_url = kernel::get_app_statics_host_url().'/'.$app_id.'/widgets';

        $this->res_dir = PUBLIC_DIR.'/app/'.$app_id.'/statics';
        $this->widgets_dir = PUBLIC_DIR.'/app/'.$app_id.'/widgets';
        $this->lang_dir = PUBLIC_DIR.'/app/'.$app_id.'/lang';
    }
    static public function get($app_id)
    {
        if (!isset(self::$__instance[$app_id])) {
            self::$__instance[$app_id] = new app($app_id);
        }

        return self::$__instance[$app_id];
    }

    public function controller($controller)
    {
        return kernel::single($this->app_id . '_ctl_' . $controller, $this);
    }

    public function _($key)
    {
        return lang::_($this->lang_dir, $key);
    }

    public function getConf($key)
    {
        return $this->setting()->get_conf($key);
    }

    public function setting()
    {
        if(!$this->__setting) {
            $this->__setting = new base_setting($this);
        }

        return $this->__setting;
    }
}